<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<title></title>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <%@include file="/WEB-INF/common/hplus-js.jsp" %>
    <style type="text/css">
    #required{
	color:red;
}
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/regenerant/edit" class="form-horizontal m-t" id="userForm" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="Tid" value="${id}">

                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span >*</span>名称：</label>
                                <div class="col-sm-6">
                                    <input type="text"  name="name"   class="form-control" aria-required="true" value="${goods.name}"  required="required" minlength="1"  placeholder="输入类型名称">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span>*</span>排序：</label>
                                <div class="col-sm-6">
                                    <input type="number"  name="sorting"  id="order" value="${goods.sorting}" class="form-control" aria-required="true"  required="required" minlength="1"  placeholder="回收价格排序 值越小越靠前 0 第一">
                                </div>
                            </div>

                            <c:if test="${goods.tyepC!=8}">
                            <div class="form-group" id="price">
                                <label class="col-sm-3 control-label"><span id="required">* 价格 kg/元：</span></label>
                                <div class="col-sm-6">
                                    <input type="text" value="${goods.money}" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" aria-required="true"  required="required" name="money" id="number"  class="form-control"  minlength="1"  placeholder="价格  (kg/元)"
                                    >
                                </div>
                            </div>
                            </c:if>

                            <c:if test="${goods.tyepC==8}">
                            <div class="form-group" id="price">
                                <label class="col-sm-3 control-label"><span id="required">* 价格 kg/元：</span></label>
                                <div class="col-sm-6">
                                    <input type="text" value="N.NN" aria-required="true"  required="required" name="money" id="number"  class="form-control"  minlength="1"  placeholder="电子电器类设置 N.NN"
                                    >
                                </div>
                            </div>
                            </c:if>




                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span ></span>说明：</label>
                                <div class="col-sm-6">
                                    <input type="text"  value="${goods.remark}"  name="remark" aria-required="true"  required="required"  class="form-control" placeholder="物品说明:20字以内"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span ></span>图片：</label>
                                <div class="col-sm-6">
                                    <input name="icon" id="icon" type="hidden">
                                    <input type="text"  id="i" class="form-control" aria-required="true"  required="required" onclick="fileclick()" placeholder="点击上传"/>
                                </div>
                            </div>


                            <div class="form-group" style="text-align: center">
                                <div class="col-sm-4 col-sm-offset-3" style="text-align: center">
                                    <button class="btn btn-primary" id="add-btn" type="button">修改</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <form id="img" action="${path}/file/uploadimage" style="display: none">
        <input type="file" id="file" onchange="upload(this.value)" name="file">
    </form>
    <%@include file="/WEB-INF/common/hplus-suggest-js.jsp"%>
    <!--手机号 生分证，表单校验插件 -->
<script src="${pageContext.request.contextPath}/assets/js/validate/dist/additional-methods.js"></script>
    
    <script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
    <script>

            $("#add-btn").click(function() {
            	var valid = $("#userForm").valid();
                var order = $("#order").val();
                if (order<0){
                    layer.msg("排序值不能小于0",{icon:5})
                    return ;
                }
            	if(valid) {

            	    if ($("#icon").val()==''){
            	        layer.msg("没有上传图片",{icon:5})
            	        return ;
                    }

            		$("#userForm").ajaxSubmit({
                        dataType: "json",
                        success: function (json) {
                            var code = json.code;
                            if(code == 0){
                            	layer.msg(json.msg, {icon: 1});
                                setTimeout(function(){
                                	window.parent.location.reload();
                                	parent.parent.layer.closeAll();
                                }, 1000);
                            }else{
                            	layer.msg(json.msg, {icon: 5,time:2000});
                            }
                        },
                        error:function(){
                        	layer.msg('添加发生错误', {icon: 5});
                        }
                    });
            	}else{
            		layer.msg("请填写完整信息！！！！", {
						icon : 5
					});
            	}
        });

            function show(val) {
                if (val==0){
                    $("#price").show();

                } else {
                    $("#price").hide();
                }
            }


            function fileclick() {
                $('#file').click();
            }
            function upload(val){
                $("#i").val(val);
                $("#img").ajaxSubmit({
                    type:'POST',
                    dataType:'json',
                    success:function (json) {
                        var code = json.code;
                        var id = json.id;
                        if (code ==0){
                            $("#icon").val(id);
                            layer.msg(json.msg,{icon:1})
                        }else {
                            layer.msg(json.msg,{icon:1})
                        }

                    }


                });
            }



    </script>

</body>
</html>
